package sort;

import java.io.BufferedInputStream;
import java.util.Scanner;

public class LCS {
    public static void main(String[] args) {
	Scanner in = new Scanner(new BufferedInputStream(System.in));
	while (in.hasNext()) {
	    String s1 = in.next();
	    String s2 = in.next();
	    int M = s1.length();
	    int N = s2.length();
	    int[][] len = new int[M + 1][N + 1];

	    for (int i = M - 1; i >= 0; i--) {
		for (int j = N - 1; j >= 0; j--) {
		    if (s1.charAt(i) == s2.charAt(j)) {
			len[i][j] = len[i + 1][j + 1] + 1;
		    } else {
			len[i][j] = Math.max(len[i + 1][j], len[i][j + 1]);
		    }
		}
	    }
	    for (int i = 0; i < len.length; i++) {
		for (int j = 0; j < len[i].length; j++) {
		    System.out.print(len[i][j] + " ");
		}
		System.out.println();
	    }
	    System.out.print("==============\n" + len[0][0] + ", ");

	    int i = 0, j = 0;
	    while (i < M && j < N) {
		if (s1.charAt(i) == s2.charAt(j)) {
		    System.out.print(s1.charAt(i));
		    i++;
		    j++;
		} else if (len[i + 1][j] >= len[i][j + 1]) {
		    i++;
		} else {
		    j++;
		}
	    }
	    System.out.println();
	}
    }
}
